package com.finer.service.impl;

import com.finer.dao.FinerPermissionDao;
import com.finer.entity.human.FinerPermission;
import com.finer.service.FinerPermissionService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 权限表(FinerPermission)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:38
 */
@Service("finerPermissionService")
public class FinerPermissionServiceImpl implements FinerPermissionService {
    @Resource
    private FinerPermissionDao finerPermissionDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public FinerPermission queryById(Integer id) {
        return this.finerPermissionDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param finerPermission 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FinerPermission> queryByPage(FinerPermission finerPermission, PageRequest pageRequest) {
        long total = this.finerPermissionDao.count(finerPermission);
        return new PageImpl<>(this.finerPermissionDao.queryAllByLimit(finerPermission, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param finerPermission 实例对象
     * @return 实例对象
     */
    @Override
    public FinerPermission insert(FinerPermission finerPermission) {
        this.finerPermissionDao.insert(finerPermission);
        return finerPermission;
    }

    /**
     * 修改数据
     *
     * @param finerPermission 实例对象
     * @return 实例对象
     */
    @Override
    public FinerPermission update(FinerPermission finerPermission) {
        this.finerPermissionDao.update(finerPermission);
        return this.queryById(finerPermission.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.finerPermissionDao.deleteById(id) > 0;
    }
}
